<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改用户')" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">

        <form class="form-horizontal m" id="editForm" th:object="${info}" style="border: 0px solid red;">

            <input name="id"  type="hidden"  th:field="*{id}" />

            <div class="form-group">
                <label class="col-sm-3 control-label ">用户名：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text"  th:field="*{userName}" required />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">账号：</label>
                <div class="col-sm-8">
                    <input name="userName"  placeholder="请输入账号" class="form-control" type="text"  th:field="*{account}" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">登录密码：</label>
                <div class="col-sm-8">
                    <input name="password" id="password" placeholder="请输入密码"
                           class="form-control" type="password" maxlength="30"  th:field="*{password}" required />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">用户状态：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" th:checked="${info.status == 1 ? true : false}">
                        <span></span>
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">用户角色：</label>
                <div class="col-sm-8">
                    <select name="roleId" id="roleId" class="form-control m-b" >
                        <option ></option>
                    </select>
                </div>
            </div>

        </form>
    </div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: select2-js" />
	<script type="text/javascript">
        var prefix = ctx + "sys/user";
        var roleId = [[${info.roleId}]];
        loadRole("roleId",roleId);

        $("#editForm").validate({
            onkeyup: false,
            rules: {
                account:{
                    required: true,
                    minlength: 2,
                    maxlength:16
                },
                userName: {
                    required: true,
                    minlength: 2,
                    maxlength:16
                },
                password: {
                    required: true,
                    minlength: 4,
                    maxlength:20
                },
                roleId: {
                    required: true,
                }
            },
            messages: {
                password: {
                    minlength: "密码必须5个字符以上",
                    maxlength: "密码必须20字符以下"
                }
            },
            focusCleanup: true
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	        	var data = $("#editForm").serializeJson();
	        	console.log(JSON.stringify(data));
	        	var status = $("input[id='status']").is(':checked') == false ? 0 : 1;
	        	data.status = status;
	        	$.operate.save(prefix + "/updateById", data,null,true);
	        }
	    }
    </script>
</body>
</html>